/*
 * @Author: lerio.cheng
 * @Date:   2017-02-22 16:44:17
 * @Last Modified by:   DELL
 * @Last Modified time: 2017-02-24 12:49:10
 */

'use strict';

app.controller('housePicsTempletCtrl', function($scope, tipService, $http, rest, $state, ngDialog, user, $location,uploadConf,mapSev,uiLoad) {

    $scope.postParem = {
        landlordId: user.get('landlordId'),
    };

	$scope.housePicsTemplet = true;

	$scope.column2 = 0;      //分栏
    $scope.maxImgNum = 100;    //最大图片数量
    $scope.imgNew= [
        {
            text:'卧室图片',
            name: 'bedRoom',
            value: [],
            picType: 0,
            hink: '至少两张'
        },
        {
            text:'客厅图片',
            name: 'livingRoom',
            value: [],
            picType: 1,
            hink: '至少两张'
        },
        {
            text:'卫生间图片',
            name: 'bathRoom',
            value: [],
            picType: 2,
            hink: '至少两张'
        },
        {
            text:'厨房图片',
            name: 'kitchenRoom',
            value: [],
            picType: 3,
            hink: '至少两张'
        },
        {
            text:'周边环境',
            name: 'environment',
            value: [],
            picType: 4,
            hink: '至少两张'
        },
        {
            text:'房门照片',
            name: 'door',
            value: [],
            picType: 10,
            hink: '至少两张'
        },
        {
            text:'合同图片集合',
            name: 'livingRoom',
            value: [],
            picType: 11,
        },
        {
            text:'路牌照片',
            name: 'bathRoom',
            value: [],
            picType: 12,
        },
        {
            text:'半开门照片',
            name: 'kitchenRoom',
            value: [],
            picType: 13,
        },
        {
            text:'房产证照片',
            name: 'environment',
            value: [],
            picType: 14,
        },
        {
            text:'小区门口照片',
            name: 'door',
            value: [],
            picType: 15,
        }
    ];

    uploadConf.column2 = $scope.column2;
    uploadConf.maxImgNum =  $scope.maxImgNum;
    uploadConf.imgNew = $scope.imgNew;

    //
    $scope.saveData = function () {

        $scope.postParem.name = $scope.picTemplateName;

        var PicTemplateContent = [];
        for (var i in uploadConf.imgNew) {
            for (var j in uploadConf.imgNew[i].value) {
                PicTemplateContent.push({picPath: uploadConf.imgNew[i].value[j],picType: uploadConf.imgNew[i].picType});
            }
        }

        if (!$scope.picTemplateName) {
            tipService.show("body", {
                message: "图片模板名称未填写",
                notice: "danger"
            }, 3);
            return false;
        }

        for (var i=0; i<=5; i++ ) {
           if ($scope.imgNew[i].value.length < 2) {
            tipService.show("body", {
                message: "房屋图片每项至少上传两张照片",
                notice: "danger"
            }, 3);
            return false;
          }
        }

        for (var j=6; j<$scope.imgNew.length; j++ ) {
            console.log(j)
            console.log($scope.imgNew[j])
           if ($scope.imgNew[j].value.length < 1) {
            tipService.show("body", {
                message: "装修图片每项至少上传一张照片",
                notice: "danger"
            }, 3);
            return false;
          }
        }

        $scope.postParem.picTemplateContent = PicTemplateContent;

        rest.post({
            methodId: '3010',
            data: $scope.postParem,
            success: function(res) {
                if (res.code == 0) {
                    tipService.show("body", {
                        message: "图片模板保存成功,跳转中......"
                    }, 3);
                    $state.go('app.houseOwner.modelList');
                    console.log($scope.params);
                    // flag = true;
                } else {
                    tipService.show("body", {
                        message: res.res.msg,
                        notice: "danger"
                    }, 3);
                }
                $scope.disable_save_btn = false;
            },
            error: function() {
                $scope.disable_save_btn = false;
            }
        })
     }

    $scope.backList = function() {
        $state.go('app.houseOwner.modelList');
    }



})
